﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ToolsLayer;
using System.Data;
using Webcar.BLL;

namespace Webcar.Car
{
    public partial class GpsSummaryReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.SelectByMonth1.SearchClick +=new EventHandler(SelectByMonth1_SearchClick);
            if (this.IsPostBack) return;
        }

        void SelectByMonth1_SearchClick(object sender, EventArgs e)
        {
            string start = this.SelectByMonth1.GetStartDate();
            string end = this.SelectByMonth1.GetEndDate();
            string sql = @"select sum(a.total_gps) total_gps,sum(a.cs_car_num) cs_car_num,sum(a.cs_num) cs_num,sum(a.yj_car_num) yj_car_num,sum(a.yj_num) yj_num,
                            sum(a.cs_stop_num) cs_stop_num,sum(a.yj_stop_num) yj_stop_num,sum(a.cf_num) cf_num,sum(a.cf_zj_num) cf_zj_num
                            ,b.dept_name from bs_gps_summary a,dept b 
                            where a.dept_code=b.dept_code and a.dept_code in (select dept_code from bs_man_dept where man_code='{0}') and isnull(b.del_flag,'F')='F'
                            and a.ny between '{1}' and '{2}'
                            group by b.dept_name";
            sql = string.Format(sql, CurrentUser.LoginUserID,start,end);

            this.GridView1.DataSource = DB.ExecuteDataset(sql);
            this.GridView1.DataBind();
            
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                DataSet data = this.GridView1.DataSource as DataSet;
                DataTable table = data.Tables[0];
                e.Row.Cells[0].Text = "合计：";
                e.Row.Cells[1].Text = table.Compute("sum(total_gps)", "").ToString();
                e.Row.Cells[2].Text = table.Compute("sum(cs_car_num)", "").ToString();
                e.Row.Cells[3].Text = table.Compute("sum(cs_num)", "").ToString();
                e.Row.Cells[4].Text = table.Compute("sum(yj_car_num)", "").ToString();
                e.Row.Cells[5].Text = table.Compute("sum(cs_stop_num)", "").ToString();
                e.Row.Cells[6].Text = table.Compute("sum(yj_stop_num)", "").ToString();
                e.Row.Cells[7].Text = table.Compute("sum(cf_num)", "").ToString();
                e.Row.Cells[8].Text = table.Compute("sum(cf_zj_num)", "").ToString();
                e.Row.Font.Bold = true;
                
            }
        }
    }
}
